var followModesStore = null;
var userIdStore = null;
var formg = null;
var formg2 = null;
var gridStoreg = null;
var gridStoreTab_2 = null;
var gridStoreTab_3 = null;
var gridStoreTab_4 = null;
var gridStoreTab_5 = null;
var groupStore = null;
var userStore = null;
var resCode = 'menu_0003_0001';

//是否存在认领
function getGiveUpCustomer(projectId, customerPhone) {
	if (projectId == "-1") {
		projectId = "";
	}
	//是否存在认领
	var params = {
		projectId : projectId,
		customerPhone : customerPhone,
		page : 1,
		limit : 10,
	};
	Ext.Ajax
			.request({
				url : contextPath + "/customer/giveUp/giveUpList",
				params : params,
				method : 'POST',
				callback : function(options, success, response) {
					var obj = JSON.parse(response.responseText);
					if (obj.rows != null && obj.rows.length >= 0) {
						Ext.Msg
								.confirm(
										'温馨提示',
										'该客户为已放弃客户，是否认领?',
										function(btn, text) {
											if (btn == 'yes') {
												var selectWindow = Ext
														.create(
																'component.giveCustomer.selectWindow',
																{
																	callbackFun : function(
																			record) {
																		var result = Ext.JSON
																				.decode(record);
																		Ext.Ajax
																				.request({
																					url : contextPath
																							+ "/customer/giveUp/getGiveUpCustomer",
																					params : {
																						customerId : result.id
																					},
																					method : 'POST',
																					callback : function(
																							options,
																							success,
																							response) {
																						var obj = JSON
																								.parse(response.responseText);
																						if (obj.res == 1) {
																							Ext.MessageBox
																									.alert(
																											'提示',
																											'认领成功!');
																							setTimeout(
																									function() {
																										parent
																												.openMenu(
																														'0',
																														'menu_0006_0001',
																														'menu_0006',
																														'客户列表',
																														'/customer/customer/index');
																									},
																									2000);

																						} else {
																							Ext.MessageBox
																									.alert(
																											'提示',
																											obj.resMsg);
																						}
																					}
																				});
																	},
																	resourcesCode : 'menu_0006_0020',
																	projectId : obj.rows[0].projectId,
																	customerPhone : obj.rows[0].customerPhone,
																	giveUpStatus : '1'

																});
												selectWindow.show();
											}
										});
					} else {
						Ext.Msg
								.confirm(
										'温馨提示',
										'该客户不存在于本项目! 是否需要新增?',
										function(btn, text) {
											if (btn == 'yes') {
												var addCusUrl = jypath
														+ "/customer/customer/toAdd?menu=menu_0003_0001&customerPhone="
														+ customerPhone;
												window.location.href = addCusUrl;
											}
										});
					}
				}

			});

}

Ext
		.onReady(function() {
			groupStore = new Ext.data.Store(
					{
						fields : [ "name", "id" ],
						proxy : {
							type : 'ajax',
							url : jypath
									+ '/customer/customer/returnGroupList?resourcesCode=menu_0006_0001',
							reader : {
								type : 'json',
								root : 'root' // 数据
							}
						}
					});

			userStore = new Ext.data.Store(
					{
						fields : [ "userName", "id" ],
						proxy : {
							type : 'ajax',
							url : jypath
									+ '/customer/customer/returnGroupUserList?resourcesCode=menu_0006_0001',
							reader : {
								type : 'json',
								root : 'root' // 数据
							}
						}
					});

			var followModesStoreList = [ {
				"value" : "1",
				"text" : "来电"
			}, {
				"value" : "2",
				"text" : "来访"
			}, {
				"value" : "3",
				"text" : "信息"
			}, {
				"value" : "4",
				"text" : "去电"
			}, {
				"value" : "5",
				"text" : "拜访"
			}, {
				"value" : "7",
				"text" : "微信"
			} ];

			followModesStore = Ext.data.Store({
				autoDestroy : true,
				fields : [ "value", "text" ],
				data : followModesStoreList
			});

			userIdStore = new Ext.data.Store(
					{
						fields : [ "userName", "id" ],
						proxy : {
							type : 'ajax',
							url : jypath
									+ '/customer/customer/userByProjectIdForGroup?resourcesCode=menu_0006_0001',
							reader : {
								type : 'json',
								root : 'root' // 数据
							}
						}
					});

            var intentionLevelStoreList = [
                {"value":"2","text":"A"},
                {"value":"3","text":"B"},
                {"value":"4","text":"C"},
                {"value":"5","text":"D"}
            ];
            var intentionLevelStore = Ext.data.Store({
                autoDestroy: true,
                fields :["value","text"],
                data : intentionLevelStoreList
            });

			var customerStatusStoreList = [{
				"value" : "7",
				"text" : "来电"
			}, {
				"value" : "2",
				"text" : "来访"
			}, {
				"value" : "3",
				"text" : "认筹"
			}, {
				"value" : "4",
				"text" : "认购"
			}, {
				"value" : "5",
				"text" : "签约"
			}, {
				"value" : "8",
				"text" : "退房"
			} ];
			if (payDepositOff) {
				customerStatusStoreList = customerStatusStoreList.del(2);
			}
			var customerStatusStore = Ext.data.Store({
				autoDestroy : true,
				fields : [ "value", "text" ],
				data : customerStatusStoreList
			});

			var processStatusStoreList = [{
				"value" : "",
				"text" : "全部"
			}, {
				"value" : "1",
				"text" : "已跟进"
			}, {
				"value" : "0",
				"text" : "未跟进"
			}];
			var processStatusStore = Ext.data.Store({
				autoDestroy : true,
				fields : [ "value", "text" ],
				data : processStatusStoreList
			});
			

			//置业动机
			var rqTheirMotivesStore = new Ext.data.Store({
				singleton : true,
				autoDestroy : true,
				fields : [ "id", "codeName", "delFlag" ],
				proxy : {
					type : 'ajax',
					url : contextPath
							+ '/system/baseCodeValue/getCodeNameByType',
					reader : {
						type : 'json',
						root : 'root' // 数据
					}
				},
				autoLoad : false
			});
			//	rqTheirMotivesStore.load({
			//		callback: function(records, operation, success){
			//			rqTheirMotivesStore.filter("delFlag", 0);
			//		}
			//	});

			//居住地 - 省份
			var peResidenceProvinceIdStore = new Ext.data.Store({
				singleton : true,
				autoDestroy : true,
				fields : [ "id", "areaName", "delFlag" ],
				proxy : {
					type : 'ajax',
					url : contextPath + '/customer/customer/provList',
					reader : {
						type : 'json',
						root : 'sheng' // 数据
					}
				},
				autoLoad : true
			});

			//居住地 - 城市
			var peResidenceCityIdStore = new Ext.data.Store({
				singleton : true,
				autoDestroy : true,
				fields : [ "id", "areaName" ],
				proxy : {
					type : 'ajax',
					url : contextPath + '/customer/customer/cityList',
					reader : {
						type : 'json',
						root : 'root' // 数据
					}
				}
			});

			//居住地 - 区域
			var peResidenceAreaIdStore = new Ext.data.Store({
				singleton : true,
				autoDestroy : true,
				fields : [ "id", "areaName" ],
				proxy : {
					type : 'ajax',
					url : contextPath + '/customer/customer/areaList',
					reader : {
						type : 'json',
						root : 'root' // 数据
					}
				}
			});

			var ftContactWayStore = new Ext.data.Store({
				singleton : true,
				autoDestroy : true,
				fields : [ "id", "codeName", "delFlag" ],
				proxy : {
					type : 'ajax',
					url : contextPath
							+ '/system/baseCodeValue/getCodeNameByType',
					reader : {
						type : 'json',
						root : 'root' // 数据
					}
				},
				autoLoad : false
			});

            var informedWayStore = new Ext.data.Store({
                singleton : true,
                autoDestroy : true,
                fields : [ "id", "codeName", "delFlag" ],
                proxy : {
                    type : 'ajax',
                    url : contextPath
                    + '/system/baseCodeValue/getCodeNameByType',
                    reader : {
                        type : 'json',
                        root : 'root' // 数据
                    }
                },
                autoLoad : false
            });

			formg2 = Ext
					.create(
							"Ext.form.Panel",
							{
								minHeight : 60,
								title : "客户查询",
								collapsible : true, // 可折叠
								autoScroll : false, // 自动创建滚动条
								defaultType : 'textfield',
								defaults : {
									anchor : '100%'
								},
								fieldDefaults : {
									labelWidth : 100,
									labelAlign : "right",
									margin : "5 20 5 5"
								},
								items : [ {
									xtype : "container",
									layout : "column",
									items : [
											{
												xtype : 'textfield',
												fieldLabel : '客户查询',
												name : 'condition',
												width : 400,
												hideTrigger : true,
												id : 'condition',
												regex : /^(1[3|4|5|6|7|8|9]\d{9}$|[\u4e00-\u9fa5_a-zA-Z]{1,20})$/,
												regexText : "输入手机号(11位)或者姓名(20位以内)",
												enableKeyEvents : true,
												listeners : {
													render : function(self,
															opts) {
														$("#condition-inputEl")
																.attr(
																		"placeholder",
																		'请输入客户姓名或手机号码查询');
													},
													specialkey : function(
															field, e) {
														var secSearchForm = formg2
																.getForm();
														if (!secSearchForm
																.isValid()) {
															return false;
														}
														if (e.getKey() == e.ENTER) {
															var condition = Ext
																	.getCmp(
																			'condition')
																	.getValue();
															var customerName = "";
															var customerPhone = "";
															if (!isNaN(condition)) {
																customerPhone = condition;
															} else {
																customerName = condition;
															}
															var reg = /^1[3|4|5|6|7|8|9]\d{9}$/;
															if (customerPhone) {
																if (!reg
																		.test(customerPhone)) {
																	Ext.MessageBox
																			.alert(
																					"系统提示",
																					"请输入正确的手机号码!");
																	return false;
																}
															}
															var projectId = Ext.getCmp("cbstore").getValue();
															if(projectId == "-1"){
																Ext.MessageBox.alert("系统提示", "请选择项目!");
																return false;
															}
															var url = jypath
																	+ '/customer/customer/findCustomerByNameOrPhone'
															if (!condition) {
																url = jypath
																		+ '/customer/customer/customerList'
															}
															var projectId = Ext
																	.getCmp(
																			'cbstore')
																	.getValue();
															var customerMainTabpanel = Ext
																	.getCmp('customer_main_tabpanel');
															var itemId = customerMainTabpanel.activeTab.itemId;
															if (itemId == "tab_1") {
																gridStoreg
																		.getProxy().extraParams.projectId = projectId;
																gridStoreg
																		.getProxy().extraParams.customerPhone = customerPhone;
																gridStoreg
																		.getProxy().extraParams.customerName = customerName;
																gridStoreg
																		.getProxy().url = url;
																gridStoreg
																		.load({
																			callback : function(
																					records,
																					operation,
																					success) {
																				var gridStoreCount = gridStoreg
																						.getCount();
																				if (customerPhone) {
																					if (gridStoreCount == 0) {

																						Ext.Msg
																								.confirm(
																										'温馨提示',
																										'该客户不存在于本项目! 是否需要新增?',
																										function(
																												btn,
																												text) {
																											if (btn == 'yes') {
																												var addCusUrl = jypath
																														+ "/customer/customer/toAdd?menu=menu_0003_0001&customerPhone="
																														+ customerPhone;
																												window.location.href = addCusUrl;
																											}
																										});
																					} else{
																						var record = records[0].data;
																						var outPermissionData = record.outPermissionData;
																						if (outPermissionData) {
																							gridStoreg
																									.removeAll();
																							cusInfo(
																									record,
																									gridStoreg);
																						}
																					}
																				}
																			}
																		});
																var pagingTool = Ext
																		.getCmp("pagingTool");
																pagingTool
																		.moveFirst();// 跳至第一页
															} else if (itemId == "tab_2") {
																gridStoreTab_2
																		.getProxy().url = url;
																gridStoreTab_2
																		.getProxy().extraParams.projectId = projectId;
																gridStoreTab_2
																		.getProxy().extraParams.customerPhone = customerPhone;
																gridStoreTab_2
																		.getProxy().extraParams.customerName = customerName;
																gridStoreTab_2
																		.load();
																var pagingTool = Ext
																		.getCmp("pagingTool_2");
																pagingTool
																		.moveFirst();// 跳至第一页
															/*} else if (itemId == "tab_3") {
																gridStoreTab_3
																		.getProxy().url = url;
																gridStoreTab_3
																		.getProxy().extraParams.projectId = projectId;
																gridStoreTab_3
																		.getProxy().extraParams.customerPhone = customerPhone;
																gridStoreTab_3
																		.getProxy().extraParams.customerName = customerName;
																gridStoreTab_3
																		.load();
																var pagingTool = Ext
																		.getCmp("pagingTool_3");
																pagingTool
																		.moveFirst();// 跳至第一页
*/															} else if (itemId == "tab_4") {
																gridStoreTab_4
																		.getProxy().url = url;
																gridStoreTab_4
																		.getProxy().extraParams.projectId = projectId;
																gridStoreTab_4
																		.getProxy().extraParams.customerPhone = customerPhone;
																gridStoreTab_4
																		.getProxy().extraParams.customerName = customerName;
																gridStoreTab_4
																		.load();
																var pagingTool = Ext
																		.getCmp("pagingTool_4");
																pagingTool
																		.moveFirst();// 跳至第一页
															} else if (itemId == "tab_5") {
																gridStoreTab_5
																		.getProxy().url = url;
																gridStoreTab_5
																		.getProxy().extraParams.projectId = projectId;
																gridStoreTab_5
																		.getProxy().extraParams.tabType = '5';
																gridStoreTab_5
																		.getProxy().extraParams.fillInfoDay = '1';
																gridStoreTab_5
																		.getProxy().extraParams.customerPhone = customerPhone;
																gridStoreTab_5
																		.getProxy().extraParams.customerName = customerName;
																gridStoreTab_5
																		.load();
																var pagingTool = Ext
																		.getCmp("pagingTool_5");
																pagingTool
																		.moveFirst();// 跳至第一页
															}
														}
													}
												}
											},
											{
												margin : "5 20 5 5",
												xtype : "button",
												text : "查询",
												handler : function() {
													var secSearchForm = formg2
															.getForm();
													if (!secSearchForm
															.isValid()) {
														return false;
													}
													var condition = Ext.getCmp(
															'condition')
															.getValue();
													var projectId = Ext.getCmp("cbstore").getValue();
													console.log(projectId)
													if(projectId == "-1"){
														Ext.MessageBox.alert("系统提示", "请选择项目!");
														return false;
													}
													var customerName = "";
													var customerPhone = "";
													if (!isNaN(condition)) {
														customerPhone = condition;
													} else {
														customerName = condition;
													}
													var reg = /^1[3|4|5|6|7|8|9]\d{9}$/;
													if (customerPhone) {
														if (!reg
																.test(customerPhone)) {
															Ext.MessageBox
																	.alert(
																			"系统提示",
																			"请输入正确的手机号码!");
															return false;
														}
													}

													var url = jypath
															+ '/customer/customer/findCustomerByNameOrPhone'
													if (!condition) {
														url = jypath
																+ '/customer/customer/customerList'
													}
													var projectId = Ext.getCmp(
															'cbstore')
															.getValue();

													var customerMainTabpanel = Ext
															.getCmp('customer_main_tabpanel');
													var itemId = customerMainTabpanel.activeTab.itemId;
													if (itemId == "tab_1") {
														gridStoreg.getProxy().extraParams.projectId = projectId;
														gridStoreg.getProxy().extraParams.customerPhone = customerPhone;
														gridStoreg.getProxy().extraParams.customerName = customerName;
														gridStoreg.getProxy().url = url;
														var pagingTool = Ext
																.getCmp("pagingTool");
														pagingTool.moveFirst();// 跳至第一页
														gridStoreg.getProxy().extraParams.projectId = projectId;
														gridStoreg.getProxy().extraParams.customerPhone = customerPhone;
														gridStoreg.getProxy().extraParams.customerName = customerName;
														gridStoreg.getProxy().url = url;
														gridStoreg
																.load({
																	callback : function(
																			records,
																			operation,
																			success) {
																		var gridStoreCount = gridStoreg
																				.getCount();
																		if (customerPhone) {
																			if (gridStoreCount == 0) {
																				getGiveUpCustomer(
																						projectId,
																						customerPhone);

																			} else {
																				var record = records[0].data;
																				var outPermissionData = record.outPermissionData;
																				if (outPermissionData) {
																					gridStoreg
																							.removeAll();
																					cusInfo(
																							record,
																							gridStoreg);
																				}
																			}
																		}
																	}
																});
													} else if (itemId == "tab_2") {
														gridStoreTab_2
																.getProxy().url = url;
														gridStoreTab_2
																.getProxy().extraParams.projectId = projectId;
														gridStoreTab_2
																.getProxy().extraParams.customerPhone = customerPhone;
														gridStoreTab_2
																.getProxy().extraParams.customerName = customerName;
														//gridStoreTab_2.load();
														var pagingTool = Ext
																.getCmp("pagingTool_2");
														pagingTool.moveFirst();// 跳至第一页
													/*} else if (itemId == "tab_3") {
														gridStoreTab_3
																.getProxy().url = url;
														gridStoreTab_3
																.getProxy().extraParams.projectId = projectId;
														gridStoreTab_3
																.getProxy().extraParams.customerPhone = customerPhone;
														gridStoreTab_3
																.getProxy().extraParams.customerName = customerName;
														//gridStoreTab_3.load();
														var pagingTool = Ext
																.getCmp("pagingTool_3");
														pagingTool.moveFirst();// 跳至第一页
*/													} else if (itemId == "tab_4") {
														gridStoreTab_4
																.getProxy().url = url;
														gridStoreTab_4
																.getProxy().extraParams.projectId = projectId;
														gridStoreTab_4
																.getProxy().extraParams.customerPhone = customerPhone;
														gridStoreTab_4
																.getProxy().extraParams.customerName = customerName;
														//gridStoreTab_4.load();
														var pagingTool = Ext
																.getCmp("pagingTool_4");
														pagingTool.moveFirst();// 跳至第一页
													} else if (itemId == "tab_5") {
														gridStoreTab_5
																.getProxy().url = url;
														gridStoreTab_5
																.getProxy().extraParams.projectId = projectId;
														gridStoreTab_5
																.getProxy().extraParams.tabType = '5';
														gridStoreTab_5
																.getProxy().extraParams.fillInfoDay = '1';
														gridStoreTab_5
																.getProxy().extraParams.customerPhone = customerPhone;
														gridStoreTab_5
																.getProxy().extraParams.customerName = customerName;
														//gridStoreTab_4.load();
														var pagingTool = Ext
																.getCmp("pagingTool_5");
														pagingTool.moveFirst();// 跳至第一页
													}
												}
											},
											{
												margin : "5 20 5 5",
												xtype : "button",
												text : "保存列表设置",
												handler : function() {
													//获取选中的列表，所有列表以选中的列表设置为准
													var customerMainTabpanel = Ext
															.getCmp('customer_main_tabpanel');
													var items = customerMainTabpanel.activeTab.items;
													//获取列表隐藏字段
													customerHideField = "";
													var columns = items.items[0].columns
													for (var i = 0; i < columns.length; i++) {
														if (columns[i].hidden) {
															if (i < (columns.length - 1)) {
																customerHideField += columns[i].dataIndex
																		+ ",";
															} else {
																customerHideField += columns[i].dataIndex;
															}
														}
													}
													//获取列表排序字段
													customerSort = "";
													var sorter = items.items[0].store.sorters;
													for (var i = 0; i < sorter.length; i++) {
														var sortName = sorter.getAt(i).property;
														if("id" === sortName){
															sortName = "t.id";
														}
														customerSort = sortName
																+ " "
																+ sorter
																		.getAt(i).direction;
													}
													//保存列表设置
													Ext.Ajax
															.request({
																url : contextPath
																		+ '/customer/customer/userSettings',
																params : {
																	"customerSort" : customerSort,
																	"customerHideField" : customerHideField
																},
																method : 'POST',
																success : function(
																		response) {
																	var text = Ext
																			.decode(response.responseText);
																	if (text.res == "1") {
																		Ext.MessageBox
																				.alert(
																						"系统提示",
																						"设置成功");
																	} else {
																		Ext.MessageBox
																				.alert(
																						"系统提示",
																						"设置失败");
																	}
																}
															});
												}
											} ]
								} ]
							})

			var formg3_column_1 = {
				items : [ {
					xtype : 'container',
					layout : 'hbox',
					items : [
							{
								xtype : "textfield",
								name : "resourcesCode",
								value : resourcesCode,
								hidden : true
							},
							{
								xtype : "textfield",
								name : "resourcesName",
								value : "resName_cus_list",
								hidden : true
							},
							{
								xtype : 'combobox',
								id : 'cbstore',
								store : cbstore,
								displayField : "projectName",
								valueField : "id",
								fieldLabel : '项目名称',
								queryMode : 'local',
								typeAhead : true,
								listeners : {
									'change' : function(value) {
										if (value.lastValue
												&& value.lastValue != "-1") {
											Ext.getCmp("batchFenPei").enable();
										} else {
											Ext.getCmp("batchFenPei").disable();
										}
										
										userIdStore.load({
											callback : function(value) {
												//加载组团数据
												var count = userIdStore
														.getCount();
												if (count > 0) {
													var id = userIdStore.getAt(
															0).get("id");
													Ext.getCmp('user')
															.setValue(id);
												}
											}
										});
										//Ext.getCmp('customerOrigin').setValue("");
										Ext.getCmp('rqTheirMotives').setValue(
												"");
										Ext.getCmp('ftContactWay').setValue("");
										//客户性质
										/*customerOriginStore.load({
											params : {
												'projectId' : value.lastValue,
												'typeValue' : 'customerNature'
											}
										});*/
										//置业动机
										rqTheirMotivesStore.load({
											params : {
												'projectId' : value.lastValue,
												'typeValue' : 'theirMotives'
											}
										});
										//联系方式
                                        ftContactWayStore.load({
                                            params : {
                                                'projectId' : value.lastValue,
                                                'typeValue' : 'contactWay'
                                            }
                                        });
                                        //获知途径
                                        informedWayStore.load({
                                            params : {
                                                'projectId' : value.lastValue,
                                                'typeValue' : 'informedWay'
                                            }
                                        });

										var url = jypath
												+ '/customer/customer/customerList';

										gridStoreg.getProxy().extraParams.projectId = value.lastValue;
										gridStoreg.getProxy().extraParams.customerName = "";
										gridStoreg.getProxy().extraParams.customerPhone = "";
										Ext.getCmp("pagingTool").moveFirst();

										gridStoreTab_2.getProxy().url = url;
										gridStoreTab_2.getProxy().extraParams.projectId = value.lastValue;
										gridStoreTab_2.getProxy().extraParams.customerName = "";
										gridStoreTab_2.getProxy().extraParams.customerPhone = "";
										Ext.getCmp("pagingTool_2").moveFirst();

										/*gridStoreTab_3.getProxy().url = url;
										gridStoreTab_3.getProxy().extraParams.projectId = value.lastValue;
										gridStoreTab_3.getProxy().extraParams.customerName = "";
										gridStoreTab_3.getProxy().extraParams.customerPhone = "";
										Ext.getCmp("pagingTool_3").moveFirst();*/

										gridStoreTab_4.getProxy().url = url;
										gridStoreTab_4.getProxy().extraParams.projectId = value.lastValue;
										gridStoreTab_4.getProxy().extraParams.customerName = "";
										gridStoreTab_4.getProxy().extraParams.customerPhone = "";
										Ext.getCmp("pagingTool_4").moveFirst();

										gridStoreTab_5.getProxy().url = url;
										gridStoreTab_5.getProxy().extraParams.projectId = value.lastValue;
										gridStoreTab_5.getProxy().extraParams.customerName = "";
										gridStoreTab_5.getProxy().extraParams.customerPhone = "";
										Ext.getCmp("pagingTool_5").moveFirst();
									}
								}
							}, {
								xtype : 'combobox',
								id : 'user',
								store : userIdStore,
								displayField : "userName",
								valueField : "id",
								fieldLabel : '经纪人',
								name : 'userCode',
								queryMode : 'local',
								labelWidth : 120
							}, {
								xtype : 'combobox',
								id : 'ftContactWay',
								store : ftContactWayStore,
								displayField : "codeName",
								valueField : "id",
								fieldLabel : '首次接触方式',
								typeAhead : true,
								name : 'ftContactWay',
								queryMode : 'local',
								labelWidth : 120
							}, {
                            xtype : 'combobox',
                            id : 'informedWay',
                            store : informedWayStore,
                            displayField : "codeName",
                            valueField : "id",
                            fieldLabel : '获知途径',
                            typeAhead : true,
                            name : 'informedWay',
                            queryMode : 'local',
                            labelWidth : 120
                        	} ]
				} ]
			};

			var formg3_column_2 = {
				items : [ {
					xtype : 'container',
					layout : 'hbox',
					items : [ {
						xtype : "radiogroup",
						id : "radioId",
						fieldLabel : "未跟进情况",
						width : 320,
						items : [ {
							boxLabel : '≥7天',
							inputValue : '1',
							id : 'radio1',
							name : "lastFollowTimeRadio",
							listeners : {
								'change' : function(value) {
									Ext.getCmp('lastFts1').setDisabled(true);
									Ext.getCmp('lastFts2').setDisabled(true);
								}
							}
						}, {
							boxLabel : '≥15天',
							inputValue : '2',
							id : 'radio2',
							name : "lastFollowTimeRadio",
							listeners : {
								'change' : function(value) {
									Ext.getCmp('lastFts1').setDisabled(true);
									Ext.getCmp('lastFts2').setDisabled(true);
								}
							}
						}, {
							boxLabel : '>=30天',
							inputValue : '3',
							id : 'radio3',
							name : "lastFollowTimeRadio",
							listeners : {
								'change' : function(value) {
									Ext.getCmp('lastFts1').setDisabled(true);
									Ext.getCmp('lastFts2').setDisabled(true);
								}
							}
						} ]
					}, {
						xtype : "textfield",
						id : 'lastFts1',
						name : "lastFollowTimeStart",
						width : 60,
						regex : /^\d+$/,
						regexText : "未跟进情况只能为数字",
						listeners : {
							'change' : function(value) {
								Ext.getCmp('radio1').setDisabled(true);
								Ext.getCmp('radio2').setDisabled(true);
								Ext.getCmp('radio3').setDisabled(true);
								Ext.getCmp('radio4').setDisabled(true);
							}
						}
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 5
					}, {
						xtype : "textfield",
						name : "lastFollowTimeEnd",
						id : 'lastFts2',
						width : 60,
						hideLabel : true,
						regex : /^\d+$/,
						regexText : "未跟进情况只能为数字",
						listeners : {
							'change' : function(value) {
								Ext.getCmp('radio1').setDisabled(true);
								Ext.getCmp('radio2').setDisabled(true);
								Ext.getCmp('radio3').setDisabled(true);
								Ext.getCmp('radio4').setDisabled(true);
							}
						}
					}, {
						xtype : "datefield",
						id: "ftContactTimeBefore",
						name : "ftContactTimeBefore",
						fieldLabel : "首次接触日期",
						format : 'Y-m-d',
						width : 210
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 10
					}, {
						xtype : "datefield",
						id: "ftContactTimeAfter",
						name : "ftContactTimeAfter",
						format : 'Y-m-d',
						width : 110,
						hideLabel : true
					} ]
				} ]
			};

			var formg3_column_3 = {
				items : [ {
					xtype : "container",
					layout : "hbox",
					items : [ {
						xtype : 'combobox',
						id : 'customerStar',
						store : intentionLevelStore,
						displayField : "text",
						valueField : "value",
						fieldLabel : '意向等级',
						typeAhead : true,
						name : 'intentionLevel'
					}, {
						xtype : 'combobox',
						id : 'customerStatus',
						store : customerStatusStore,
						displayField : "text",
						valueField : "value",
						fieldLabel : '客户状态',
						typeAhead : true,
						name : 'customerStatus'
					}, {
						xtype : 'combobox',
						id : 'processStatus',
						store : processStatusStore,
						displayField : "text",
						valueField : "value",
						fieldLabel : '分配跟进状态',
						typeAhead : true,
						name : 'processStatus'
					} ]
				}, {
					xtype : "container",
					layout : "hbox",
					items : [ {
						xtype : "datefield",
						name : "createTimeBefore",
						fieldLabel : "录入日期",
						format : 'Y-m-d',
						width : 210,
						hidden : true
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 10,
						hidden : true
					}, {
						xtype : "datefield",
						name : "createTimeAfter",
						format : 'Y-m-d',
						width : 110,
						hideLabel : true,
						hidden : true
					}, {
						xtype : 'combobox',
						id : 'rqTheirMotives',
						store : rqTheirMotivesStore,
						displayField : "codeName",
						valueField : "id",
						fieldLabel : '置业动机',
						typeAhead : true,
						name : 'rqTheirMotives'
					}, {
						xtype : "textfield",
						name : "peAgeStart",
						id : "peAgeStart",
						fieldLabel : "客户年龄",
						maxLength : 3,
						width : 210,
						regex : /^\d+$/,
						regexText : "年龄只能为数字"
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 10
					}, {
						xtype : "textfield",
						name : "peAgeEnd",
						id : "peAgeEnd",
						maxLength : 3,
						width : 110,
						hideLabel : true,
						regex : /^\d+$/,
						regexText : "年龄只能为数字"
					} ]
				}, {
					xtype : "container",
					layout : "hbox",
					items : [ {
						xtype : "datefield",
						name : "lastFollowTimeBefore",
						fieldLabel : "最后跟进日期",
						format : 'Y-m-d',
						width : 210
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 10
					}, {
						xtype : "datefield",
						name : "lastFollowTimeAfter",
						format : 'Y-m-d',
						width : 110,
						hideLabel : true
					}, {
						xtype : 'combobox',
						id : 'peResidenceProvinceId',
						store : peResidenceProvinceIdStore,
						displayField : "areaName",
						valueField : "id",
						fieldLabel : '居住地',
						typeAhead : true,
						name : 'peResidenceProvinceId',
						queryMode : 'local',
						width : 190,
						listeners : {
							'change' : function(value) {
								Ext.getCmp('peResidenceCityId').setValue("");
								Ext.getCmp('peResidenceAreaId').setValue("");
								peResidenceCityIdStore.load({
									params : {
										'id' : value.lastValue
									}
								});
							}
						}
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 10
					}, {
						xtype : 'combobox',
						id : 'peResidenceCityId',
						store : peResidenceCityIdStore,
						displayField : "areaName",
						valueField : "id",
						typeAhead : true,
						name : 'peResidenceCityId',
						queryMode : 'local',
						width : 85,
						listeners : {
							'change' : function(value) {
								Ext.getCmp('peResidenceAreaId').setValue("");
								peResidenceAreaIdStore.load({
									params : {
										'id' : value.lastValue
									}
								});
							}
						}
					}, {
						margin : "0 5 0 5",
						xtype : 'displayfield',
						value : '-',
						hideLabel : true,
						width : 10
					}, {
						xtype : 'combobox',
						id : 'peResidenceAreaId',
						store : peResidenceAreaIdStore,
						displayField : "areaName",
						valueField : "id",
						typeAhead : true,
						queryMode : 'local',
						width : 85,
						name : 'peResidenceAreaId'
					} ]
				} ]
			};

			formg = Ext
					.widget({
						region : 'north',
						xtype : 'form',
						frame : true,
						minHeight : 170,
						title : "查询条件",
						collapsible : true, //可折叠
						autoScroll : false, //自动创建滚动条
						defaultType : 'textfield',
						defaults : {
							anchor : '100%'
						},
						fieldDefaults : {
							margin : 2,
							labelWidth : 80,
							labelAlign : "right",
							margin : "5 0 0 0"
						},

						items : [ {
							xtype : 'container',
							layout : 'vbox',
							fieldDefaults : {
								labelAlign : 'left',
								msgTarget : 'side',
								margin : 20,
								anchor : '60%',
								labelWidth : 120
							},
							defaults : {
								border : false,
								xtype : 'container',
								flex : 1,
								layout : 'anchor'
							},
							items : [ formg3_column_1, formg3_column_2 ]
						}, {
							xtype : 'fieldset',
							title : '更多...',
							collapsible : true,
							collapsed : true,
							defaults : {
								labelWidth : 89,
								anchor : '100%',
								layout : {
									type : 'vbox',
									defaultMargins : {
										top : 10,
										right : 10,
										bottom : 10,
										left : 10
									}
								}
							},
							items : [ formg3_column_3 ]
						} ],
						buttons : [
								{
									hidden : customerAdd,
									xtype : "button",
									text : "新增",
									handler : function() {
										var currProjectId = Ext.getCmp(
												"cbstore").getValue();
										var tabKey = "customer_"
												+ currProjectId;
										var url = '/customer/customer/toAdd?menu='
												+ resCode
												+ "&projectId="
												+ currProjectId + "&1=1";
										parent.openMenu('0', tabKey, '',
												'新增客户', url);
									}
								},
								{
									xtype : "button",
									text : "批量导入",
									handler : function() {
										var selectProjectId = Ext.getCmp(
												"cbstore").getValue();
										if (selectProjectId
												&& selectProjectId == "-1") {
											Ext.MessageBox.alert("系统提示",
													"请选择项目");
											return;
										}
										var fromPanel = Ext
												.create(
														"Ext.form.Panel",
														{
															collapsible : false,
															autoScroll : false,
															defaultType : 'textfield',
															defaults : {
																anchor : '100%'
															},
															fieldDefaults : {
																flex : 1
															},
															items : [ {
																xtype : 'filefield',
																fieldLabel : '导入excel',
																emptyText : '请上传excel文件',
																id : 'multipartFile',
																name : 'multipartFile',
																msgTarget : 'side',
																allowBlank : false,
																anchor : '95%',
																buttonConfig : {
																	iconCls : 'silk-folder'
																},
																buttonText : '选择文件'
															} ]
														});

										var window = Ext
												.create(
														'Ext.Window',
														{
															title : "批量导入",
															width : 300,
															height : 150,
															closable : true,
															modal : true,
															headerPosition : 'top',
															items : [ fromPanel ],
															buttons : [
																	{
																		xtype : "button",
																		text : "开始导入",
																		iconCls : 'icon-save',
																		handler : function() {
																			var form = fromPanel
																					.getForm();
																			var selectProjectId = Ext
																					.getCmp(
																							"cbstore")
																					.getValue();
																			if (selectProjectId == "") {
																				Ext.MessageBox
																						.alert(
																								"系统提示",
																								"请选择项目");
																				return;
																			}
																			if (form
																					.isValid()) {
																				var params = form
																						.getValues();
																				params.projectId = selectProjectId;
																				form
																						.submit({
																							timeout : 7200,
																							url : contextPath
																									+ '/customer/import/importExcel',
																							params : params,
																							method : "POST",
																							waitMsg : '正在上传...',
																							success : function(
																									form,
																									action) {
																								Ext.MessageBox
																										.alert(
																												"系统提示",
																												"导入成功");
																							},
																							failure : function(
																									form,
																									action) {
																								var obj = JSON
																										.parse(action.response.responseText);
																								var res = obj.res;
																								if (res == "1") {
																									var result = obj.obj;
																									var successCount = result.successCount;
																									var errorCount = result.errorCount;
																									var totalCount = successCount
																											+ errorCount;
																									var batchId = result.batchId;
																									var showMsg = "总计："
																											+ totalCount
																											+ "条;成功:"
																											+ successCount
																											+ "条;失败:"
																											+ errorCount
																											+ "条;";
																									if (errorCount > 0) {
																										Ext.MessageBox
																												.confirm(
																														"提示",
																														showMsg
																																+ ",是否下载错误数据?",
																														function(
																																btn,
																																txt) {
																															if (btn == "yes") {
																																//下载
																																var downloadUrl = contextPath
																																		+ "/customer/import/download?batchId="
																																		+ batchId;
																																location.href = downloadUrl;
																															} else {
																																console
																																		.log("canel")
																															}
																														});
																									} else {
																										Ext.MessageBox
																												.alert(
																														"提示",
																														showMsg);
																									}
																								} else {
																									Ext.MessageBox
																											.alert(
																													"提示",
																													"导入失败");
																								}

																							}
																						});
																			}
																		}
																	},
																	{
																		xtype : "button",
																		text : "模板下载",
																		iconCls : 'icon-save',
																		handler : function() {
																			location.href = customerTemplet;
																		}
																	} ]
														});
										window.show();
									}
								},
								{
									hidden : customerExport,
									xtype : "button",
									text : "导出列表",
									handler : function() {
										//验证年龄是否正确
										var chkPeAgeStart = Ext.getCmp(
												'peAgeStart').getValue();
										var reg_age = /^\d+$/;
										if (chkPeAgeStart != null
												&& chkPeAgeStart != "") {
											if (!reg_age.test(chkPeAgeStart)
													|| chkPeAgeStart > 999) {
												Ext.Msg.alert('提示', '年龄只能为正整数');
												return;
											}
										}
										var chkPeAgeEnd = Ext
												.getCmp('peAgeEnd').getValue();
										if (chkPeAgeEnd != null
												&& chkPeAgeEnd != "") {
											if (!reg_age.test(chkPeAgeEnd)
													|| chkPeAgeStart > 999) {
												Ext.Msg.alert('提示', '年龄只能为正整数');
												return;
											}
										}

										if (Ext.getCmp('cbstore').getValue() == null
												|| Ext.getCmp('cbstore')
														.getValue() == ""
												|| Ext.getCmp('cbstore')
														.getValue() == "-1") {
											Ext.Msg.alert('提示', '请选择项目');
											return;
										}

										var records = gridg.getSelectionModel()
												.getSelection();
										var ids = "";
										for (var ii = 0; ii < records.length; ii++) {
											if (ids) {
												ids += ",";
											}
											ids += records[ii].data.id;
										}

										var condition = Ext.getCmp('condition')
												.getValue();
										var customerPhone = "";

										if (condition) {
											if (!isNaN(condition)) {
												customerPhone = condition;
												var reg = /^1[3|4|5|6|7|8|9]\d{9}$/;
												if (customerPhone) {
													if (!reg
															.test(customerPhone)) {
														Ext.MessageBox.alert(
																"系统提示",
																"请输入正确的手机号码!");
														return false;
													}
												}
											} else {
												condition = encodeURI(encodeURI(condition));
											}
										}

										var value = formg.getForm().getValues();
										location.href = jypath
												+ '/customer/customer/expExcel?value='
												+ JSON.stringify(value)
												+ '&ids=' + ids + '&condition='
												+ condition;
									}
								},
								{
									xtype : "button",
									text : "查询",
									handler : function() {
										//未跟进情况redio
										var ckRadioIdValue = Ext.getCmp(
												'radioId').getChecked();
										var ckRadioId = "";
										Ext.Array
												.each(
														ckRadioIdValue,
														function(item) {
															ckRadioId += item.inputValue;
														});
										gridStoreg.getProxy().extraParams.lastFollowTimeRadio = ckRadioId;

										//验证年龄是否正确
										var chkPeAgeStart = Ext.getCmp(
												'peAgeStart').getValue();
										var reg_age = /^\d+$/;
										if (chkPeAgeStart != null
												&& chkPeAgeStart != "") {
											if (!reg_age.test(chkPeAgeStart)
													|| chkPeAgeStart > 999) {
												Ext.Msg.alert('提示', '年龄只能为正整数');
												return;
											}
										}
										var chkPeAgeEnd = Ext
												.getCmp('peAgeEnd').getValue();
										if (chkPeAgeEnd != null
												&& chkPeAgeEnd != "") {
											if (!reg_age.test(chkPeAgeEnd)
													|| chkPeAgeStart > 999) {
												Ext.Msg.alert('提示', '年龄只能为正整数');
												return;
											}
										}

										if (Ext.getCmp('cbstore').getValue() == ""
												|| Ext.getCmp('cbstore')
														.getValue() == null) {
											Ext.Msg.alert('提示', '请选择项目');
											return;
										}
										//当选择首触时间时，首触方式必填
										console.log(Ext.getCmp('ftContactTimeBefore').getValue())
										if (Ext.getCmp('ftContactTimeBefore').getValue() != null
											|| Ext.getCmp('ftContactTimeAfter').getValue() != null) {
											if(Ext.getCmp('ftContactWay').getValue() == ""
												 || Ext.getCmp('ftContactWay').getValue() == null){
												Ext.Msg.alert('提示', '请选择首次接触方式');
												return;
											}
										}

										var url = jypath
												+ '/customer/customer/customerList';
										var customerMainTabpanel = Ext
												.getCmp('customer_main_tabpanel');
										var itemId = customerMainTabpanel.activeTab.itemId;
										if (itemId == "tab_1") {
											gridStoreg.getProxy().url = url;
											gridStoreg.getProxy().extraParams.projectId = Ext
													.getCmp('cbstore')
													.getValue();
											gridStoreg.getProxy().extraParams.customerName = "";
											gridStoreg.getProxy().extraParams.customerPhone = "";
											gridStoreg.load();
											var pagingTool = Ext
													.getCmp("pagingTool");
											pagingTool.moveFirst();// 跳至第一页
										} else if (itemId == "tab_2") {
											gridStoreTab_2.getProxy().url = url;
											gridStoreTab_2.getProxy().extraParams.projectId = Ext
													.getCmp('cbstore')
													.getValue();
											gridStoreTab_2.getProxy().extraParams.customerName = "";
											gridStoreTab_2.getProxy().extraParams.customerPhone = "";
											gridStoreTab_2.load();
											var pagingTool = Ext
													.getCmp("pagingTool_2");
											pagingTool.moveFirst();// 跳至第一页
										/*} else if (itemId == "tab_3") {
											gridStoreTab_3.getProxy().url = url;
											gridStoreTab_3.getProxy().extraParams.projectId = Ext
													.getCmp('cbstore')
													.getValue();
											gridStoreTab_3.getProxy().extraParams.customerName = "";
											gridStoreTab_3.getProxy().extraParams.customerPhone = "";
											gridStoreTab_3.load();
											var pagingTool = Ext
													.getCmp("pagingTool_3");
											pagingTool.moveFirst();// 跳至第一页
*/										} else if (itemId == "tab_4") {
											gridStoreTab_4.getProxy().url = url;
											gridStoreTab_4.getProxy().extraParams.projectId = Ext
													.getCmp('cbstore')
													.getValue();
											gridStoreTab_4.getProxy().extraParams.customerName = "";
											gridStoreTab_4.getProxy().extraParams.customerPhone = "";
											gridStoreTab_4.load();
											var pagingTool = Ext
													.getCmp("pagingTool_4");
											pagingTool.moveFirst();// 跳至第一页
										} else if (itemId == "tab_5") {
											gridStoreTab_5.getProxy().url = url;
											gridStoreTab_5.getProxy().extraParams.projectId = Ext
													.getCmp('cbstore')
													.getValue();
											gridStoreTab_5.getProxy().extraParams.customerName = "";
											gridStoreTab_5.getProxy().extraParams.customerPhone = "";
											gridStoreTab_5.load();
											var pagingTool = Ext
													.getCmp("pagingTool_5");
											pagingTool.moveFirst();// 跳至第一页
										}
									}
								},
								{
									xtype : "button",
									text : "清空",
									handler : function() {
										formg.getForm().reset();
										//清空内容,初始化项目名称及经纪人
										var id = cbstore.getAt(0).get("id");
										Ext.getCmp('cbstore').setValue(id)

										id = userIdStore.getAt(0).get("id");
										Ext.getCmp('user').setValue(id);

										//未跟进情况
										Ext.getCmp('radio1').setDisabled(false);
										Ext.getCmp('radio2').setDisabled(false);
										Ext.getCmp('radio3').setDisabled(false);
										Ext.getCmp('radio4').setDisabled(false);
										Ext.getCmp('lastFts1').setDisabled(
												false);
										Ext.getCmp('lastFts2').setDisabled(
												false);
									}
								} ]
					});
			var gridCommonFields = [ "id", "customerName", "customerPhone",
					"customerSex", "customerStatus", "peBirth",
					"intentionLevel", "ftContactWay", "ftContactContent","ftContactContent1",
					"followContent", "userName", "followType",
					"lastFollowTime", "followMonth", "customerTradeStatus",
					"projectId", "followId", "outPermissionData","processStatus",
					"questionnaire", "cusTag", "fillInfoDay", "customerOriginName","orgStores", "isCallToVisit", "dataAuthority"];

			gridStoreg = Ext.create('Ext.data.Store', {
				fields : gridCommonFields,
				pageSize : 10, // 页容量5条数据
				// 是否在服务端排序 （true的话，在客户端就不能排序）
				remoteSort : false,
				proxy : {
					type : 'ajax',
					url : jypath + '/customer/customer/customerList',
					actionMethods : {
						read : 'POST'
					},
					reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
						type : 'json', // 返回数据类型为json格式
						root : 'rows', // 数据
						totalProperty : 'total' // 数据总条数
					},
					extraParams : {
						tabType : '1'
					}
				},
				autoLoad : false
			// 即时加载数据

			});

			gridStoreTab_2 = Ext.create('Ext.data.Store', {
				fields : gridCommonFields,
				pageSize : 10, // 页容量5条数据
				// 是否在服务端排序 （true的话，在客户端就不能排序）
				remoteSort : false,
				proxy : {
					type : 'ajax',
					url : jypath + '/customer/customer/customerList',
					actionMethods : {
						read : 'POST'
					},
					reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
						type : 'json', // 返回数据类型为json格式
						root : 'rows', // 数据
						totalProperty : 'total' // 数据总条数
					},
					extraParams : {
						tabType : '2'
					}
				},
				autoLoad : false
			// 即时加载数据
			});

			/*gridStoreTab_3 = Ext.create('Ext.data.Store', {
				fields : gridCommonFields,
				pageSize : 10, // 页容量5条数据
				// 是否在服务端排序 （true的话，在客户端就不能排序）
				remoteSort : false,
				proxy : {
					type : 'ajax',
					url : jypath + '/customer/customer/customerList',
					actionMethods : {
						read : 'POST'
					},
					reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
						type : 'json', // 返回数据类型为json格式
						root : 'rows', // 数据
						totalProperty : 'total' // 数据总条数
					},
					extraParams : {
						tabType : '3'
					}
				},
				autoLoad : false
			// 即时加载数据
			});*/

			gridStoreTab_4 = Ext.create('Ext.data.Store', {
				fields : gridCommonFields,
				pageSize : 10, // 页容量5条数据
				// 是否在服务端排序 （true的话，在客户端就不能排序）
				remoteSort : false,
				proxy : {
					type : 'ajax',
					url : jypath + '/customer/customer/customerList',
					actionMethods : {
						read : 'POST'
					},
					reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
						type : 'json', // 返回数据类型为json格式
						root : 'rows', // 数据
						totalProperty : 'total' // 数据总条数
					},
					extraParams : {
						tabType : '4'
					}
				},
				autoLoad : false
			// 即时加载数据
			});

			gridStoreTab_5 = Ext.create('Ext.data.Store', {
				fields : gridCommonFields,
				pageSize : 10, // 页容量5条数据
				// 是否在服务端排序 （true的话，在客户端就不能排序）
				remoteSort : false,
				proxy : {
					type : 'ajax',
					url : jypath + '/customer/customer/customerList',
					actionMethods : {
						read : 'POST'
					},
					reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
						type : 'json', // 返回数据类型为json格式
						root : 'rows', // 数据
						totalProperty : 'total' // 数据总条数
					},
					extraParams : {
						tabType : '5',
						fillInfoDay : "1"
					}
				},
				autoLoad : false
			// 即时加载数据
			});

			userIdStore.on("beforeload", function() {
				userIdStore.proxy.extraParams.isList = 1;
				var cbstoreValue = Ext.getCmp('cbstore').getValue();
				//console.log("cbstoreValue = " + cbstoreValue);
				if (cbstoreValue == "-1") {
					userIdStore.proxy.extraParams.projectId = "";
				} else {
					userIdStore.proxy.extraParams.projectId = cbstoreValue;
				}
			});

			gridStoreg.on("beforeload", function() {
				//gridStoreg.proxy.extraParams.radioList = 123;
				Ext.apply(gridStoreg.proxy.extraParams, formg.getForm()
						.getValues());
				var cbstoreValue = Ext.getCmp('cbstore').getValue();
				if (cbstoreValue == "-1") {
					gridStoreg.proxy.extraParams.projectId = "";
				}
				var userCode = Ext.getCmp("user").getValue();
				if (userCode == "-1") {
					gridStoreg.proxy.extraParams.userCode = "";
				}
				var newResCode = resourcesCode + ",menu_0003_0001";
				gridStoreg.proxy.extraParams.resourcesCode = newResCode;
			});

			gridStoreTab_2.on("beforeload", function() {
				Ext.apply(gridStoreTab_2.proxy.extraParams, formg.getForm()
						.getValues());
				var cbstoreValue = Ext.getCmp('cbstore').getValue();
				if (cbstoreValue == "-1") {
					gridStoreTab_2.proxy.extraParams.projectId = "";
				}
				var userCode = Ext.getCmp("user").getValue();
				if (userCode == "-1") {
					gridStoreTab_2.proxy.extraParams.userCode = "";
				}
				var newResCode = resourcesCode + ",menu_0003_0001";
				gridStoreTab_2.proxy.extraParams.resourcesCode = newResCode;
			});

			/*gridStoreTab_3.on("beforeload", function() {
				Ext.apply(gridStoreTab_3.proxy.extraParams, formg.getForm()
						.getValues());
				var cbstoreValue = Ext.getCmp('cbstore').getValue();
				if (cbstoreValue == "-1") {
					gridStoreTab_3.proxy.extraParams.projectId = "";
				}
				var userCode = Ext.getCmp("user").getValue();
				if (userCode == "-1") {
					gridStoreTab_3.proxy.extraParams.userCode = "";
				}
				var newResCode = resourcesCode + ",menu_0003_0001";
				gridStoreTab_3.proxy.extraParams.resourcesCode = newResCode;
			});*/
			gridStoreTab_4.on("beforeload", function() {
				Ext.apply(gridStoreTab_4.proxy.extraParams, formg.getForm()
						.getValues());
				var cbstoreValue = Ext.getCmp('cbstore').getValue();
				if (cbstoreValue == "-1") {
					gridStoreTab_4.proxy.extraParams.projectId = "";
				}
				var userCode = Ext.getCmp("user").getValue();
				if (userCode == "-1") {
					gridStoreTab_4.proxy.extraParams.userCode = "";
				}
				var newResCode = resourcesCode + ",menu_0003_0001";
				gridStoreTab_4.proxy.extraParams.resourcesCode = newResCode;
			});

			gridStoreTab_5.on("beforeload", function() {
				Ext.apply(gridStoreTab_5.proxy.extraParams, formg.getForm()
						.getValues());
				var cbstoreValue = Ext.getCmp('cbstore').getValue();
				if (cbstoreValue == "-1") {
					gridStoreTab_5.proxy.extraParams.projectId = "";
				}
				var userCode = Ext.getCmp("user").getValue();
				if (userCode == "-1") {
					gridStoreTab_5.proxy.extraParams.userCode = "";
				}
				var newResCode = resourcesCode + ",menu_0003_0001";
				gridStoreTab_5.proxy.extraParams.resourcesCode = newResCode;
			});

			gridStoreg.on("load",
					function() {
						var totalCount = gridStoreg.getTotalCount();
						Ext.getCmp('customerTabItem_1').setTitle(
								"全部（" + totalCount + "）");
						//初始化“全部”列表的排序和隐藏字段功能，其他列表在点击tab时触发
						//排序
						if (customerSort != null && customerSort != "") {
							var sort = customerSort.split(" ");
							gridStoreg.sort(sort[0], sort[1]);
						}
						//隐藏字段
						if (customerHideField != null
								&& customerHideField != "") {
							var columns = gridg.columns;
							for (var i = 0; i < columns.length; i++) {
								if (customerHideField
										.indexOf(columns[i].dataIndex) >= 0) {
									columns[i].hide();
								}
							}
						}
					});

			gridStoreTab_2.on("load", function() {
				var totalCount = gridStoreTab_2.getTotalCount();
				Ext.getCmp('customerTabItem_2').setTitle(
						"逾期未签约（" + totalCount + "）");
			});

			/*gridStoreTab_3.on("load", function() {
				var totalCount = gridStoreTab_3.getTotalCount();
				Ext.getCmp('customerTabItem_3').setTitle(
						"待处理客户（" + totalCount + "）");
			});*/

			gridStoreTab_4.on("load", function() {
				var totalCount = gridStoreTab_4.getTotalCount();
				Ext.getCmp('customerTabItem_4').setTitle(
						"逾期未付款（" + totalCount + "）");
			});
			gridStoreTab_5.on("load", function() {
				var totalCount = gridStoreTab_5.getTotalCount();
				Ext.getCmp('customerTabItem_5').setTitle(
						"未完善客户信息（" + totalCount + "）");
			});

			var columns = [{
						text : "操作",
						dataIndex : 'id',
						locked: true,
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var rec = record/* gridg.getStore().getAt(rowIndex) */;
							var projectId = rec.get("projectId");
							var dataAuthority = record.get("dataAuthority");
							var intentionLevel = record.get("intentionLevel");
							var html = "";
							//判断是否有权限操作
							if(dataAuthority == "0"){
								if (customerEdit == false) {
									html += '<font color="#8c8c8c">编辑</font>&nbsp;&nbsp;';
								}
								if (customerAddFollow == false) {
									html += '<font color="#8c8c8c">写跟进</font>&nbsp;&nbsp;';
								}
								if (customerDistributionConsultant == false) {
									html += '<font color="#8c8c8c">分配</font>&nbsp;&nbsp;';
								}
								if (Number(rec.get("questionnaire")) > 0) {
									html += '<font color="#8c8c8c">客户问卷</font>&nbsp;&nbsp;';
								}
								if (Number(rec.get("cusTag")) > 0) {
									html += '<font color="#8c8c8c">客户标签</font>&nbsp;&nbsp;';
								}
								if (giveUpButton == false && intentionLevel != '2') {
									html += '<font color="#8c8c8c">客户放弃</font>&nbsp;&nbsp;';
								}
								if(rec.get("isCallToVisit") == "1"){
									html += '<font color="#8c8c8c">电转访</font>&nbsp;&nbsp;';
								};
								return html;
							}
							if (customerEdit == false) {
								html += '<a href="javascript:upd(' + value
										+ ')">编辑</a>&nbsp;&nbsp;';
							}
							if (customerAddFollow == false) {
								html += '<a href="javascript:genJin(' + value
										+ ',' + projectId
										+ ',' + intentionLevel + ')">写跟进</a>&nbsp;&nbsp;';
							}
							if (customerDistributionConsultant == false) {
								html += '<a href="javascript:fenPei(' + value
										+ ',' + record.raw.projectId
										+ ')">分配</a>&nbsp;&nbsp;';
							}
							if (Number(rec.get("questionnaire")) > 0) {
								html += '<a href="javascript:questionnaire('
										+ value + ',' + projectId
										+ ')">客户问卷</a>&nbsp;&nbsp;';
							}
							if (Number(rec.get("cusTag")) > 0) {
								html += '<a href="javascript:toCusTagPage('
										+ value + ',' + projectId
										+ ')">客户标签</a>&nbsp;&nbsp;';
							}
							if (giveUpButton == false && intentionLevel != '2') {
								html += '<a href="javascript:giveUpCustomer('
										+ value + ')">客户放弃</a>&nbsp;&nbsp;';
							}
							if(rec.get("isCallToVisit") == "1"){
								html += '<a href="javascript:callToVisit(' + value
									  + ',' + projectId + ')">电转访</a>&nbsp;&nbsp;';
							}
							return html;
						},
						width:300
					},
					{
						locked : true,
						text : '客户名称',
						dataIndex : 'customerName',
						width : 100,
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var projectId = record.get("projectId");
							var dataAuthority = record.get("dataAuthority");
							var id = record.get("id");
							var html = "";
							if (customerView == false && dataAuthority == "1") {
								html += '<a href="javascript:detail(' + id
										+ ',' + projectId + ',\'' + resCode
										+ '\')">' + value + '</a>&nbsp;&nbsp;';
							}else{
								html = value;
							}
							return html;
						},
					},
					{	locked : true,
						text : '联系电话',
						dataIndex : 'customerPhone',
						width : 100
					},
					{	locked : true,
						text : '客户性别',
						dataIndex : 'customerSex',
						width : 50,
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var html = "";
							if (value == 1) {
								html = '男';
							} else if (value == 2) {
								html = '女';
							}
							var dataAuthority = record.get("dataAuthority");
							var processStatus = record.get("processStatus");
							if(dataAuthority == "1" && processStatus == '0'){
								html = '<font style="color:#990033">'+html+'</font>';
							}
							return html;
						}
					}, {
						locked : true,
						text : '经纪人',
						dataIndex : 'userName',
						width : 50
					},
					{
						text : '客户状态',
						dataIndex : 'customerStatus',
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var html = '';
							if (value == 1) {
								html = '问询';
							} else if (value == 2) {
								html = '来访';
							} else if (value == 3) {
								html = '认筹';
							} else if (value == 4) {
								html = '认购';
							} else if (value == 5) {
								html = '签约';
							} else if (value == 6) {
								html = '无意向';
							} else if (value == 7) {
								html = '来电';
							} else if (value == 8) {
								html = '退房';
							}
							var processStatus = record.get("processStatus");
							if(processStatus == '0'){
								html = '<font style="color:#990033">'+html+'</font>';
							}
							return html;
						},
						width : 100
					},
					{
						text : '来电沟通内容',
						dataIndex : 'ftContactContent',
						width : 200
					},
					{
						text : '来访/电转访沟通内容',
						dataIndex : 'ftContactContent1',
						width : 200
					},
					{
						text : '最后跟进内容',
						dataIndex : 'followContent',
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var rec = record/* gridg.getStore().getAt(rowIndex) */;
							var followId = rec.get("followId");
							var followType = rec.get('followType');
							if (followType == 2) {
								var html = '<a href="#" onclick="genJinList('
										+ followId + ',' + followType
										+ ')">图片地址</a>';
								return html;
							} else if (followType == 3) {
								var html = '<a href="#" onclick="genJinList('
										+ followId + ',' + followType
										+ ')">语音地址</a>';
								return html;
							}
							if(value == null){
								return '';
							}
							var html = "";
							var processStatus = rec.get("processStatus");
							if(processStatus == '0'){
								html = '<span style="color:#990033" title="'+value+'">'+value+'</span>';
							}else{
								html = '<span title="'+value+'">'+value+'</span>';
							}
							return html;
						},
						width : 120
					},
					{
						text : '最后跟进时间',
						dataIndex : 'lastFollowTime',
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							if (value == null || value == "") {
								return "";
							}
							var html = Ext.Date.format(new Date(value), 'Y-m-d G:i:s');;
							var processStatus = record.get("processStatus");
							if(processStatus == "0"){
								html = '<font style="color:#990033">' + html + '</font>';
							}
							return html;
						},
						width : 120

					},
					{
						text : '跟进次数',
						dataIndex : 'followMonth',
						width : 50
					},
					{
						text : '意向等级',
						dataIndex : 'intentionLevel',
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var html = "";
							if (value == 2) {
								html = 'A';
							} else if (value == 3) {
								html = 'B';
							} else if (value == 4) {
								html = 'C';
							} else if (value == 5) {
								html = 'D';
							}
							var processStatus = record.get("processStatus");
							if(processStatus == "0"){
								html = '<font style="color:#990033">' + html + '</font>';
							}
							return html;
						},
						width : 50
					},
					{
						text : '是否多套交易',
						dataIndex : 'customerTradeStatus',
						renderer : function(value, cellmeta, record, rowIndex,
								columnIndex, store) {
							var rec = record/* gridg.getStore().getAt(rowIndex) */;
							var html = "";
							if (value == null || value == "") {
								return "";
							} else if (value == "4") {// 为4时为多套交易
								html = "是";
							} else if (value != "4"){
								html = "否"
							}
							var processStatus = record.get("processStatus");
							if(processStatus == "0"){
								html = '<font style="color:#990033">' + html + '</font>';
							}
							return html;
						},
						width : 50

					}, {
						text : '获知途径',
						dataIndex : 'customerOriginName',
						width : 100
					},{
                    text : '渠道机构',
                    dataIndex : 'orgStores',
                    width : 100
                }
			];

			var pagingtoolbarStoreList = [ {
				"value" : "10",
				"text" : "10"
			}, {
				"value" : "20",
				"text" : "20"
			}, {
				"value" : "50",
				"text" : "50"
			}, {
				"value" : "100",
				"text" : "100"
			}, ];

			var pagingtoolbarStore = Ext.data.Store({
				autoDestroy : true,
				fields : [ "value", "text" ],
				data : pagingtoolbarStoreList
			});

			var gridg = Ext
					.create(
							'Ext.grid.Panel',
							{

								store : gridStoreg,
								columnLines : true,
								selModel : new Ext.selection.CheckboxModel({
									checkOnly : true
								}),
								columns : columns,
								title : '客户列表',
								listeners : {
									'itemdblclick' : function(dataview, record,
											item, index, e) {
										var projectId = record.data.projectId;
										var id = record.data.id;
										var dataAuthority = record.data.dataAuthority;
										if(dataAuthority == "0"){
											return;
										}
										if (null == projectId 
												|| projectId == ""
												|| null == id || id == "") {
											return;
										}
										detail(id, projectId, resCode);
									}
								},
								dockedItems : [ {
									xtype : 'pagingtoolbar',
									store : gridStoreg, // GridPanel中使用的数据
									dock : 'bottom',
									displayInfo : true,
									emptyMsg : "没有数据",
									displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据",
									id : 'pagingTool',
									items : [ {
										xtype : 'combobox',
										store : pagingtoolbarStore,
										displayField : "text",
										valueField : "value",
										fieldLabel : '页数',
										queryMode : 'local',
										typeAhead : true,
										hideLabel : true,
										width : 60,
										value : 10,
										listeners : {
											change : function(value) {
												var pagingTool = Ext
														.getCmp("pagingTool");
												pagingTool.getStore().pageSize = value.lastValue;
												pagingTool.moveFirst();
											}
										}
									} ]
								} ],
								tbar : [ {
									text : '批量分配',
									id : "batchFenPei",
									icon : jypath
											+ '/resources/ExtJSicons/flag/flag_pink.png',
									handler : function() {
										var records = gridg.getSelectionModel()
												.getSelection();
										if (null == records || records == 0) {
											Ext.Msg.alert('提示', '请选择客户！');
											return;
										}
										var ids = "";
										for (var ii = 0; ii < records.length; ii++) {
											if (ids) {
												ids += ",";
											}
											ids += records[ii].data.id;
										}
										if (ids) {
											var projectId = Ext.getCmp(
													"cbstore").getValue();
											fenPei(ids, projectId);
										}
									}
								} ]
							});

			var gridTab_2 = Ext
					.create(
							'Ext.grid.Panel',
							{
								store : gridStoreTab_2,
								columnLines : true,
								columns : columns,
								title : '逾期未签约客户',
								listeners : {
									'itemdblclick' : function(dataview, record,
											item, index, e) {
										var projectId = record.data.projectId;
										var id = record.data.id;
										if (null == projectId
												|| projectId == ""
												|| null == id || id == "") {
											return;
										}
										detail(id, projectId, resCode);

									}
								},
								dockedItems : [ {
									xtype : 'pagingtoolbar',
									store : gridStoreTab_2, // GridPanel中使用的数据
									dock : 'bottom',
									displayInfo : true,
									emptyMsg : "没有数据",
									displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据",
									id : 'pagingTool_2',
									items : [ {
										xtype : 'combobox',
										store : pagingtoolbarStore,
										displayField : "text",
										valueField : "value",
										fieldLabel : '页数',
										queryMode : 'local',
										typeAhead : true,
										hideLabel : true,
										width : 60,
										value : 10,
										listeners : {
											change : function(value) {
												var pagingTool = Ext
														.getCmp("pagingTool_2");
												pagingTool.getStore().pageSize = value.lastValue;
												pagingTool.moveFirst();
											}
										}
									} ]
								} ]
							});

			/*var gridTab_3 = Ext
					.create(
							'Ext.grid.Panel',
							{
								store : gridStoreTab_3,
								columnLines : true,
								columns : columns,
								title : '待处理客户',
								listeners : {
									'itemdblclick' : function(dataview, record,
											item, index, e) {
										var projectId = record.data.projectId;
										var id = record.data.id;
										if (null == projectId
												|| projectId == ""
												|| null == id || id == "") {
											return;
										}
										detail(id, projectId, resCode);

									}
								},
								dockedItems : [ {
									xtype : 'pagingtoolbar',
									store : gridStoreTab_3, // GridPanel中使用的数据
									dock : 'bottom',
									displayInfo : true,
									emptyMsg : "没有数据",
									displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据",
									id : 'pagingTool_3',
									items : [ {
										xtype : 'combobox',
										store : pagingtoolbarStore,
										displayField : "text",
										valueField : "value",
										fieldLabel : '页数',
										queryMode : 'local',
										typeAhead : true,
										hideLabel : true,
										width : 60,
										value : 10,
										listeners : {
											change : function(value) {
												var pagingTool = Ext
														.getCmp("pagingTool_3");
												pagingTool.getStore().pageSize = value.lastValue;
												pagingTool.moveFirst();
											}
										}
									} ]
								} ]
							});*/

			var gridTab_4 = Ext
					.create(
							'Ext.grid.Panel',
							{
								store : gridStoreTab_4,
								columnLines : true,
								columns : columns,
								title : '逾期未付款客户',
								listeners : {
									'itemdblclick' : function(dataview, record,
											item, index, e) {
										var projectId = record.data.projectId;
										var id = record.data.id;
										if (null == projectId
												|| projectId == ""
												|| null == id || id == "") {
											return;
										}
										detail(id, projectId, resCode);
									}
								},
								dockedItems : [ {
									xtype : 'pagingtoolbar',
									store : gridStoreTab_4, // GridPanel中使用的数据
									dock : 'bottom',
									displayInfo : true,
									emptyMsg : "没有数据",
									displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据",
									id : 'pagingTool_4',
									items : [ {
										xtype : 'combobox',
										store : pagingtoolbarStore,
										displayField : "text",
										valueField : "value",
										fieldLabel : '页数',
										queryMode : 'local',
										typeAhead : true,
										hideLabel : true,
										width : 60,
										value : 10,
										listeners : {
											change : function(value) {
												var pagingTool = Ext
														.getCmp("pagingTool_4");
												pagingTool.getStore().pageSize = value.lastValue;
												pagingTool.moveFirst();
											}
										}
									} ]
								} ]
							});

			var gridTab_5 = Ext
					.create(
							"Ext.grid.Panel",
							{
								store : gridStoreTab_5,
								columnLines : true,
								columns : columns,
								title : '客户信息不完整',
								listeners : {
									'itemdblclick' : function(dataview, record,
											item, index, e) {
										var projectId = record.data.projectId;
										var id = record.data.id;
										if (null == projectId
												|| projectId == ""
												|| null == id || id == "") {
											return;
										}
										detail(id, projectId, resCode);
									}
								},
								viewConfig : {
									stripeRows : true,
									getRowClass : function(record, rowIndex,
											rowParams, store) {
										if (Number(record.get('fillInfoDay')) > 7) {
											return 'x-grid-red"';
										}
									}
								},
								dockedItems : [ {
									xtype : 'pagingtoolbar',
									store : gridStoreTab_5, // GridPanel中使用的数据
									dock : 'bottom',
									displayInfo : true,
									emptyMsg : "没有数据",
									displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据",
									id : 'pagingTool_5',
									items : [ {
										xtype : 'combobox',
										store : pagingtoolbarStore,
										displayField : "text",
										valueField : "value",
										fieldLabel : '页数',
										queryMode : 'local',
										typeAhead : true,
										hideLabel : true,
										width : 60,
										value : 10,
										listeners : {
											change : function(value) {
												var pagingTool = Ext
														.getCmp("pagingTool_5");
												pagingTool.getStore().pageSize = value.lastValue;
												pagingTool.moveFirst();
											}
										}
									} ]
								} ]
							});

			var tabs2 = Ext.widget('tabpanel', {
				region : 'center',
				layout : 'fit',
				activeTab : '1' == improvenow ? 4 : 0,
				plain : true,
				defaults : {
					autoScroll : true,
					bodyPadding : 0
				},
				id : 'customer_main_tabpanel',
				items : [ {
					id : 'customerTabItem_1',
					layout : 'fit',
					title : '全部',
					items : gridg,
					itemId : 'tab_1'
				}, {
					id : 'customerTabItem_2',
					layout : 'fit',
					title : '逾期未签约',
					items : gridTab_2,
					itemId : 'tab_2'
				/*}, {
					id : 'customerTabItem_3',
					layout : 'fit',
					title : '待处理客户',
					items : gridTab_3,
					itemId : 'tab_3'*/
				}, {
					id : 'customerTabItem_4',
					layout : 'fit',
					title : '逾期未付款',
					items : gridTab_4,
					itemId : 'tab_4'
				}, {
					id : 'customerTabItem_5',
					layout : 'fit',
					title : '未完善用户信息',
					items : gridTab_5,
					itemId : 'tab_5'
				} ],
				listeners : {
					tabchange : function(tp, p) {
						var items = p.items.items[0];
						//隐藏字段
						if (customerHideField != null
								&& customerHideField != "") {
							var columns = p.items.items[0].columns;
							for (var i = 0; i < columns.length; i++) {
								if (customerHideField
										.indexOf(columns[i].dataIndex) >= 0) {
									columns[i].hide();
								}
							}
						}
						//排序
						if (customerSort != null && customerSort != "") {
							var sort = customerSort.split(" ");
							p.items.items[0].store.sort(sort[0], sort[1]);
						}
					}
				}

			});

			var viewport = Ext.create('Ext.Viewport', {
				layout : 'border',
				items : [ formg, {
					region : 'north',
					items : formg2
				}, tabs2 ]
			});

			Ext.getCmp("condition").focus();

		});

function detail(id, projectId, resourcesCode) {
	var tabKey = "cus_" + id;
	var url = "/customer/customer/toDetail?customerId=" + id + "&projectId="
			+ projectId + "&resourcesCode=" + resourcesCode;
	parent.openMenu('0', tabKey, '', '客户详情', url)
}

function upd(id) {
	var url = "/customer/customer/toUpdate?customerId=" + id + '&1=1';
	parent.openMenu('0', id, '', '编辑客户', url);
}

function del(id) {
	Ext.MessageBox.confirm("提示", "是否删除该客户?", function(btn, txt) {
		if (btn == "yes") {
			Ext.Ajax.request({
				url : jypath + '/customer/customer/delete',
				params : {
					id : id
				},
				method : 'POST',
				callback : function(options, success, response) {
					if (success) {
						var obj = JSON.parse(response.responseText);
						if (obj.resMsg == "删除成功") {
							Ext.MessageBox.alert("系统提示", "删除客户成功");
							gridStoreg.reload();
						} else {
							Ext.MessageBox.alert("系统提示", obj.resMsg);
						}
					} else {
						Ext.MessageBox.alert("系统提示", "删除客户失败！");
					}
				}
			});
		}
	});
}

function giveUpCustomer(customerId) {

	Ext.MessageBox.confirm("提示", "请确定是否放弃选择的客户?", function(btn, txt) {
		if (btn == "yes") {
			Ext.Ajax.request({
				url : jypath + '/customer/giveUp/giveUpCustomer',
				params : {
					customerId : customerId
				},
				method : 'POST',
				callback : function(options, success, response) {
					if (success) {
						var obj = JSON.parse(response.responseText);
						if (obj.res == "0") {
							Ext.MessageBox.alert("系统提示", obj.resMsg);
						} else {
							Ext.MessageBox.alert("系统提示", "放弃客户成功");
							gridStoreg.load();
						}
					} else {
						Ext.MessageBox.alert("系统提示", "放弃客户失败！");
					}
				}
			});
		}
	});

}

function genJin(id, projectId, intentionLevel) {

    var intentionLevelStoreList = [
        {"value":"2","text":"A"},
        {"value":"3","text":"B"},
        {"value":"4","text":"C"},
        {"value":"5","text":"D"}
    ];
    var intentionLevelStoreList2 = [
        {"value":"3","text":"B"},
        {"value":"4","text":"C"},
        {"value":"5","text":"D"}
    ];
    var intentionLevelStore = Ext.data.Store({
        autoDestroy: true,
        fields :["value","text"],
        data : intentionLevelStoreList
    });
    var intentionLevelStore2 = Ext.data.Store({
        autoDestroy: true,
        fields :["value","text"],
        data : intentionLevelStoreList2
    });

	var fromPanel = Ext.create("Ext.form.Panel", {
		collapsible : false,
		autoScroll : false,
		defaultType : 'textfield',
		defaults : {
			anchor : '100%'
		},
		fieldDefaults : {
			flex : 1
		},
		items : [ {
            xtype:'combobox',
            id:'intentionLevel',
            store: intentionLevelStore,
            displayField: "text",
            valueField: "value",
            fieldLabel:'<font style="color:#e90000;">*</font>意向等级',
            typeAhead: true,
            name:'intentionLevel',
            allowBlank:true,
            blankText:'不能为空',
            listeners: {
                afterRender: function(combo) {
                    if(intentionLevel == "2"){
                        combo.setReadOnly(true);
                    }else{
                    	combo.bindStore(intentionLevelStore2);
					}
                    combo.setValue(intentionLevel + '');
                }
            },
            typeAhead:false,
			editable: false
        },{
			xtype : 'combobox',
			id : 'followMode',
			store : followModesStore,
			displayField : "text",
			valueField : "value",
			fieldLabel : '<font style="color:#e90000;">*</font>跟进方式',
			width : 200,
			typeAhead : true,
			name : 'followMode',
			allowBlank : false,
			blankText : '不能为空',
			editable : false
		}, {
			xtype : 'textarea',
			name : 'followContents',
			fieldLabel : '<font style="color:#e90000;">*</font>跟进内容',
			allowBlank : false,
			blankText : '不能为空'
		}, {
			xtype : "container",
			layout : "hbox",
			items : [ {
				xtype : "datefield",
				id : "nextFollowQ",
				name : "nextFollowQ",
				fieldLabel : "下次提醒时间",
				format : 'Y-m-d',
				minWidth : 200
			}, {
				xtype : "timefield",
				id : "nextFollowH",
				name : "nextFollowH",
				format : 'G:i',
				minWidth : 100
			} ]
		}, {
			xtype : 'textarea',
			name : 'nextFollowContent',
			fieldLabel : '下次提醒内容'
		} ]
	});
	var infoPanel = Ext.create("Ext.form.Panel", {
		collapsible : false,
		autoScroll : false,
		layout : {
			align : 'middle',
			pack : 'center',
			type : 'hbox'
		},
		items : [ {
			xtype : 'displayfield',
			value : '温馨提示：记得完善客户信息哦！',
		} ]
	});
	var window = Ext.create('Ext.Window', {
		title : "写跟进",
		width : 500,
		height : 300,
		closable : true,
		modal : true,
		items : [ fromPanel, infoPanel ],
		buttons : [ {
			xtype : "button",
			id : 'followSaveButton',
			text : "保存",
			iconCls : 'icon-save',
			handler : function() {

				Ext.getCmp("followSaveButton").hide();
				var form = fromPanel.getForm();
				// var nextFollowQ=form.findField("nextFollowQ").getValue();
				var intentionLevel = form.findField("intentionLevel").getValue();
				console.log("intentionLevel = " + intentionLevel);
				var nextFollowH = form.findField("nextFollowH").getValue();
				var fom = formg.getForm();
				//var projectId = fom.findField("cbstore").getValue();
				if (form.isValid()) {
					Ext.Ajax.request({
						// +'&nextFollowQ='+nextFollowQ
						url : contextPath
								+ '/customer/customer/addFollow?customerId='
								+ id + '&projectId=' + projectId
								+ '&nextFollowH=' + nextFollowH,
						params : form.getValues(),
						callback : function(options, success, response) {
							if (success) {
								var obj = JSON.parse(response.responseText);
								if (obj.res == "1") {
									Ext.MessageBox.alert("系统提示", "写跟进成功");
									gridStoreg.load();
									gridStoreTab_2.load();
									//gridStoreTab_3.load();
									gridStoreTab_4.load();
									gridStoreTab_5.load();
									window.close();
								} else {
									Ext.MessageBox.alert("系统提示", obj.resMsg);
								}
							} else {
								Ext.MessageBox.alert("系统提示", "系统异常!");
							}
							Ext.getCmp("followSaveButton").show();
						}

					});
				}
			}
		} ]
	});
	window.show();
}

function fenPei(id, projectId) {
	groupStore.load({
		params : {
			'projectId' : projectId
		}
	});
	var fromPanel = Ext.create("Ext.form.Panel", {
		defaultType : 'textfield',
		defaults : {
			anchor : '100%'
		},
		fieldDefaults : {
			flex : 1
		},
		items : [ {
			xtype : 'combobox',
			id : 'oo',
			store : groupStore,
			displayField : "name",
			valueField : "id",
			fieldLabel : '销售组名称',
			width : 200,
			listeners : {
				'change' : function(value) {
					Ext.getCmp('userId').setValue("");
					userStore.load({
						params : {
							'salesGroupId' : value.lastValue
						}
					});
				}
			},
			name : 'projectId',
			queryMode : 'local',
			editable : false,
			allowBlank : false,
			blankText : '请选择销售组'
		}, {
			xtype : 'combobox',
			id : 'userId',
			store : userStore,
			displayField : "userName",
			valueField : "id",
			fieldLabel : '经纪人',
			width : 200,
			name : 'consultantUserId',
			queryMode : 'local',
			editable : false,
			allowBlank : false,
			blankText : '请选择经纪人'
		} ]
	});
	var window = Ext
			.create(
					'Ext.Window',
					{
						title : "分配",
						width : 300,
						height : 150,
						plain : true,
						modal : true,
						headerPosition : 'top',
						items : [ fromPanel ],
						buttons : [ {
							xtype : "button",
							text : "保存",
							iconCls : 'icon-save',
							handler : function() {
								var form = fromPanel.getForm();
								if (form.isValid()) {
									Ext.Ajax
											.request({
												url : contextPath
														+ '/customer/customer/distributionConsultant?customerId='
														+ id,
												params : form.getValues(),
												callback : function(options,
														success, response) {
													if (success) {
														var obj = JSON
																.parse(response.responseText);
														if (obj.res == "1") {
															Ext.MessageBox
																	.alert(
																			"系统提示",
																			"分配成功");
															gridStoreg.load();
															window.close();
														} else {
															Ext.MessageBox
																	.alert(
																			"系统提示",
																			obj.resMsg);
														}
													} else {
														Ext.MessageBox
																.alert("系统提示",
																		"系统异常!");
													}
												}

											});
								}

							}
						} ]
					});
	window.show();
}

function genJinList(id, type) {

	var gridStoreg_1 = Ext.create('Ext.data.Store', {
		fields : [ "id", "smallUrl", "createTime" ],
		pageSize : 10, // 页容量5条数据
		// 是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort : false,
		proxy : {
			type : 'ajax',
			url : jypath + '/customer/customer/imageList?objectId=' + id
					+ '&imgType=4',
			actionMethods : {
				read : 'POST'
			},
			reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type : 'json', // 返回数据类型为json格式
				root : 'rows', // 数据
				totalProperty : 'total' // 数据总条数
			}
		},
		autoLoad : true
	// 即时加载数据
	});
	var gridg = Ext
			.create(
					'Ext.grid.Panel',
					{
						minHeight : 600,
						store : gridStoreg_1,
						columnLines : true,
						columns : [
								{
									text : '创建日期',
									width : '30%',
									dataIndex : 'createTime',
									renderer : function(value) {
										return Ext.Date.format(new Date(value),
												'Y-m-d');
									}
								},
								{
									text : '附件类型',
									dataIndex : 'id',
									width : '20%',
									renderer : function(value, cellmeta,
											record, rowIndex, columnIndex,
											store) {
										var rec = gridg.getStore().getAt(
												rowIndex);
										if (type == 2) {
											return "图片";
										} else if (type == 3) {
											return "语音";
										}
									}
								},
								{
									text : '操作',
									dataIndex : 'smallUrl',
									width : '50%',
									renderer : function(value, cellmeta,
											record, rowIndex, columnIndex,
											store) {
										if (type == 2) {
											var html = '<a href="javascript:previewImg(\''
													+ value + '\')">预览</a>';
											return html;
										} else if (type == 3) {
											var html = '<audio controls="controls"> <source src="'
													+ value
													+ '" type="audio/mpeg"> </audio>'
											return html;
										}
									}
								} ],
						// title: '附件列表',
						dockedItems : [ {
							xtype : 'pagingtoolbar',
							store : gridStoreg_1, // GridPanel中使用的数据
							dock : 'bottom',
							displayInfo : true,
							emptyMsg : "没有数据",
							displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据"
						} ]
					});
	var window = Ext.create('Ext.Window', {
		title : "附件列表",
		width : 650,
		height : 300,
		// plain: true,
		modal : true,
		headerPosition : 'top',
		items : [ gridg ]
	});
	window.show();
}

function previewImg(url) {
	var imgs = "<img style='width:auto;height:100%;margin:0 auto;' src='" + url
			+ "' />";
	var window = Ext.create('Ext.Window', {
		title : "图片预览",
		width : '100%',
		height : '100%',
		autoScroll : true,
		maximizable : false,
		layout : 'fit',
		html : imgs
	});
	window.show();
}

function cusInfo(record, gridStoreg) {
	var fromPanel = Ext.create("Ext.form.Panel", {
		collapsible : false,
		autoScroll : false,
		defaultType : 'textfield',
		minHeight : 200,
		defaults : {
			anchor : '100%'
		},
		fieldDefaults : {
			flex : 1
		},
		items : [
				{
					xtype : "displayfield",
					value : "该客户已存在"
				},
				{
					xtype : 'displayfield',
					id : 'owner',
					name : 'owner',
					fieldLabel : "归属人",
					value : record.userName
				},
				{
					xtype : 'displayfield',
					name : 'followContents',
					fieldLabel : '最后跟进内容',
					value : record.followContent
				},
				{
					xtype : 'displayfield',
					name : 'lastFollowTime',
					fieldLabel : '最后跟进时间',
					value : Ext.Date.format(new Date(record.lastFollowTime),
							"Y-m-d H:i:s")

				} ]
	});
	var window = Ext.create('Ext.Window', {
		title : "温馨提示",
		width : 300,
		minHeight : 200,
		closable : true,
		modal : true,
		x : 300,
		y : 200,
		items : [ fromPanel ],
		buttons : [ {
			xtype : "button",
			text : "取消",
			icon : jypath + '/resources/ExtJSicons/cancel.png',
			handler : function() {
				gridStoreg.removeAll();
				window.close();

			}
		} ]
	});
	window.show();
}
//客户标签
function toCusTagPage(customerId, projectId) {
	location.href = jypath
			+ "/customer/customerProjectQuestion/toCusTagPage?customerId="
			+ customerId + "&projectId=" + projectId;
}
//客户问卷
function questionnaire(customerId, projectId) {
	location.href = jypath + "/customer/customer/toQuestionnaire?customerId="
			+ customerId + "&projectId=" + projectId;
}

/**
 * 电转访
 * @param id
 * @param projectId
 * @returns
 */
function callToVisit(id, projectId) {
	var callToVisitStore = Ext.data.Store({
		autoDestroy : true,
		fields : [ "value", "text" ],
		data : [{
			"value" : "1",
			"text" : "电转访"
		}]
	});
	var fromPanel = Ext.create("Ext.form.Panel", {
		defaults : {
			anchor : '100%',
			border: true,
            xtype: 'panel',
            flex: 1,
            labelWidth: 60,
            margin: '5 5 5 5',
            layout: 'anchor'
		},
		items : [{
			xtype : "container",
			layout : "hbox",
			items : [ {
	            xtype:'combobox',  
	            name:'ftContactWay',
	            fieldLabel:'<font style="color:#e90000;">*</font>接触方式',
	            store: callToVisitStore,
	            displayField: "text",           
	            valueField: "value",  
	            value: '1',
	            readOnly: true,
	            width : 175,
	            labelWidth: 60,
	            queryMode:'local'
            }, {
				xtype : "datefield",
				id : "ftContactTimes",
				name : "ftContactTimes",
				fieldLabel : '<font style="color:#e90000;">*</font>接触时间',
				format : 'Y-m-d',
				value: serverDate,
				width : 200,
				labelWidth: 80,
				labelAlign: "right",
				readOnly: true
			} ]
		},{
			xtype : 'textarea',
			name : 'ftContactContent',
			fieldLabel : '<font style="color:#e90000;">*</font>沟通内容',
			allowBlank : false,
			width : 300,
			blankText : '不能为空'
		}]
	});
	var window = Ext.create('Ext.Window', {
		title : "电转访",
		width : 400,
		height : 180,
		closable : true,
		modal : true,
		items : [ fromPanel ],
		buttons : [ {
			xtype : "button",
			id : 'callToVisitSaveButton',
			text : "保存",
			iconCls : 'icon-save',
			handler : function() {
				Ext.getCmp("callToVisitSaveButton").hide();
				var form = fromPanel.getForm();
				if (form.isValid()) {
					Ext.Ajax.request({
						url : contextPath
								+ '/customer/customer/addContactWay?customerId='
								+ id + '&projectId=' + projectId,
						params : form.getValues(),
						callback : function(options, success, response) {
							if (success) {
								var obj = JSON.parse(response.responseText);
								if (obj.res == "1") {
									Ext.MessageBox.alert("系统提示", "保存成功");
									gridStoreg.load();
									gridStoreTab_2.load();
									//gridStoreTab_3.load();
									gridStoreTab_4.load();
									gridStoreTab_5.load();
									window.close();
								} else {
									Ext.MessageBox.alert("系统提示", "保存成功");
								}
							} else {
								Ext.MessageBox.alert("系统提示", "系统异常!");
							}
							Ext.getCmp("callToVisitSaveButton").show();
						}

					});
				}else{
					Ext.getCmp("callToVisitSaveButton").show();
				}
			}
		} ]
	});
	window.show();
}
